package com.closer.server.mapper.image;

import com.closer.server.biz.images.dto.SearchRequest;
import com.closer.server.biz.images.dto.ImageVO;
import com.closer.server.support.sql.QueryWrapperHelper;
import com.mybatisflex.core.BaseMapper;
import com.closer.server.biz.images.entity.Images;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 图片资源 映射层。
 *
 * @author closer
 */
public interface ImagesMapper extends BaseMapper<Images> {

    /**
     * 根据查询参数查询图片列表
     * @param params 查询参数
     * @return 图片列表
     */
    default Page<ImageVO> getImageVOList(SearchRequest params){
        var queryWrapper = QueryWrapper.create()
                .select("images.*")
                .from("images")
                .orderBy("images.create_time desc");
        QueryWrapperHelper.eqIfPresent(queryWrapper, params.getId(), "images.id");
        QueryWrapperHelper.eqIfPresent(queryWrapper, params.getType(), "images.type");
        QueryWrapperHelper.eqIfPresent(queryWrapper, params.getEnabled(), "images.enabled");
        return paginateAs(params.getPageNumber(), params.getPageSize(), queryWrapper, ImageVO.class);
    }

}
